fprintf("\n");
fprintf("Data Source: Overall\n");
data = load('data.csv');
s = size(data)
plot(data(:,1));
len=1:length(data(:,1));
len=len';
[cA sC] = polyfit(len,data(:,1),1);
hold on;
plot(data(:,5),'r');
plot(data(:,8),'g');
legend({"Self Esteem","Illusion 1","Illusion 2"});
grid('on');
hold off;
print("InitVal.png");
len=1:length(data(:,5));
len=len';
[cA sA] = polyfit(len,data(:,5),1);
plot(data(:,5),'r',len, sA.yf,'g');
xlabel("Samples (Decreasing Self Esteem)");
ylabel("Illusion1");
title("Variation of Illusion1 with Self Esteem");
grid('on');
print("Ill1.png");
len=1:length(data(:,8));
len=len';
[cA sB] = polyfit(len,data(:,8),1);
plot(data(:,8),'r',len, sB.yf,'g');
xlabel("Samples (Decreasing Self Esteem)");
ylabel("Illusion2");
title("Variation of Illusion1 with Self Esteem");
grid('on');
print("Ill2.png");

len=1:length(data(:,5));
len=len';
[cA sA] = polyfit(len,data(:,5),1);
plot(len, sA.yf,'g',len,sB.yf,'r',len,sC.yf,'b');
xlabel("Samples (Decreasing Self Esteem)");
ylabel("Value");
title("Variation of Illusion1 and Illusion2 (Decreasing Self Esteem)");
legend({"Illusion 1","Illusion 2","Self Esteem"});
grid('on');
print("Comparison12.png");
m = 0;
f = 0;
fprintf("Number of samples: %d\n", s(1,1));
for i=1:s(1,1)
if data(i,3) == 1
m++;
male(m,:) = data(i,:);
else 
f++;
female(f,:) = data(i,:);
end;
end;
j=1;
DataStat(:,j) = statistics(data(:,2));
j++;
DataStat(:,j) = statistics(data(:,1));
j++;
DataStat(:,j) = statistics(data(:,5));
j++;
DataStat(:,j) = statistics(data(:,8));
j++;
m = size(male);
f = size(female); 
fprintf("Male: %d\n", m(1,1));
fprintf("Female: %d\n", f(1,1));
fprintf("\n");
fprintf("Statistics\n\nMeasure\t\t\tAge\t\t\tSelf Esteem\t\tIllusion1\t\tIllusion2");
measure = ["Minimum"; "1st Quartile"; "Median"; "3rd Quartile"; "Maximum"; "Mean"; "Std Deviation"; "Skewness"; "Kurtosis"];
fprintf("\n");
for i = 1:9
fprintf("\n");
fprintf(measure(i,:));
fprintf("\t\t");
for j = 1:4
fprintf("%f\t\t",DataStat(i,j));
end;
end;
hi=1;low=1;
for i=1:s(1,1)
if data(i,1) >= DataStat(4,2)
	High(hi,:)=data(i,:);
	hi++;
end;
if data(i,1) <= DataStat(2,2)
	Low(low,:)=data(i,:);
	low++;
end;
end;
fprintf("\nIndivisuals With High Self Esteem: %d", hi);
fprintf("\nIndivisuals With Low Self Esteem: %d", low);
fprintf("\nOverall\n");

m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,7) == 1
m++;
end;
end;
P(1) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,9) == 1
m++;
end;
end;
P(2) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,10) == 1
m++;
end;
end;
P(3) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,7) == 1 && data(i,9) == 1
m++;
end;
end;
P(4) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,7) == 1 && data(i,10) == 1
m++;
end;
end;
P(5) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,9) == 1 && data(i,10) == 1
m++;
end;
end;
P(6) = m/s(1,1);
P(7) = mean(data(:,6));
P(8) = mean(data(:,7));
P(9) = mean(data(:,9));
P(10) = mean(data(:,10));

data = High;

s=size(data);

fprintf("\nHigh Self Esteem\n");
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,7) == 1
m++;
end;
end;
Ph(1) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,9) == 1
m++;
end;
end;
Ph(2) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,10) == 1
m++;
end;
end;
Ph(3) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,7) == 1 && data(i,9) == 1
m++;
end;
end;
Ph(4) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,7) == 1 && data(i,10) == 1
m++;
end;
end;
Ph(5) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,9) == 1 && data(i,10) == 1
m++;
end;
end;
Ph(6) = m/s(1,1);
Ph(7) = mean(data(:,6));
Ph(8) = mean(data(:,7));
Ph(9) = mean(data(:,9));
Ph(10) = mean(data(:,10));


data = Low;

s=size(data);

fprintf("\nLow Self Esteem\n");

m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,7) == 1
m++;
end;
end;
Pl(1) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,9) == 1
m++;
end;
end;
Pl(2) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,6) == 1 && data(i,10) == 1
m++;
end;
end;
Pl(3) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,7) == 1 && data(i,9) == 1
m++;
end;
end;
Pl(4) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,7) == 1 && data(i,10) == 1
m++;
end;
end;
Pl(5) = m/s(1,1);
m=0;
for i=1:s(1,1)
if data(i,9) == 1 && data(i,10) == 1
m++;
end;
end;
Pl(6) = m/s(1,1);

Pl(7) = mean(data(:,6));
Pl(8) = mean(data(:,7));
Pl(9) = mean(data(:,9));
Pl(10) = mean(data(:,10));
Pt = [Ph;Pl];
size(Pt);
val = ["P(Q1)","P(Q2)","P(Q3)","P(Q4)","P(Q1,Q2)","P(Q1,Q3)","P(Q1,Q4)","P(Q2,Q3)","P(Q2,Q4)","P(Q3,Q4)"];
bar(flipud(Pt'));
legend({"High Self Esteem","Low Self Esteem"});
title("Comparison of probability of taking risks in different situations");
xlabel("Risk situation (refer to text)");
ylabel("Probability");
grid('on');
print("probComp.png");
